package com.qf.weektest.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Book {
    private Integer id;
    private String name;
    private String author;
    private String publish;
    private Integer sort;

    /**
     * List<Book>  -----> List<String>
     * String 的格式为 csv格式 ， csv格式是指逗号分隔的文本文件 ，  aaa,bbb,ccc
     * @param
     */
    public static List<String> bookCSVList(Integer size,List<Book> list){
        String CSVbook = null;
        List<String> CSVlist = null;
        for (int i = 0; i < list.size(); i++) {
             CSVbook = list.get(i).toCSVString();
             CSVlist = new ArrayList<>();
             CSVlist.add(CSVbook);
        }
        return CSVlist;
    }
    /**
     * 把 book 对象转换成 csv字符串
     * @return
     */
    public String toCSVString(){
        String s = this.getName()+","+this.getAuthor()+","+this.getPublish()+","+this.getSort();
        return s;
    }

}
